package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.dubbo.api.mapper.UserMapper;
import com.tanhua.model.db.User;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 用户服务接口实现类
 */
@DubboService
public class UserApiImpl implements UserApi{

    @Autowired
    private UserMapper userMapper;


    /**
     * 根据条件查询tb_user表 用户对象
     * @param user
     * @return
     */
    @Override
    public User find(User user) {
        return userMapper.selectOne(Wrappers.<User>lambdaQuery()
                .eq(StringUtils.isNotEmpty(user.getMobile()),User::getMobile, user.getMobile())
                .eq(null != user.getId(), User::getId, user.getId())
                .eq(StringUtils.isNotEmpty(user.getHxUser()), User::getHxUser, user.getHxUser()));
    }

    /**
     * 注册用户
     * @param user
     * @return
     */
    @Override
    public Long add(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    /**
     * 修改用户信息
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }
}
